package com.example.testfragment;

import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends FragmentActivity {
	
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_layout);
		Button btn= (Button)findViewById(R.id.show1);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
				FirstFragment f = new FirstFragment();
				ft.addToBackStack(null);
				ft.replace(R.id.container, f);
				ft.commit();
			}
		});
		
		btn=(Button)findViewById(R.id.show2);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
				SecondFragment f = new SecondFragment();
				ft.addToBackStack(null);
				ft.replace(R.id.container, f);
				ft.commit();
			}
		});
		
		btn = (Button)findViewById(R.id.addBackStack);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
				BackstackFragment f = new BackstackFragment();
				ft.addToBackStack(null);
				ft.replace(R.id.container, f);
				ft.commit();
			}
		});
			btn = (Button)findViewById(R.id.alert);
			btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				MyDialogFragment df = new MyDialogFragment();
//				df.show(getSupportFragmentManager(), "fragmentname");
				
				customDialogFragment cdf = new customDialogFragment();
				cdf.show(getSupportFragmentManager(), "fragementname");
			}
		});
		
		
		
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		FirstFragment f = new FirstFragment();
		ft.add(R.id.container, f);
		ft.commit();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
